#!/bin/sh

function menu_install(){
echo -e "  AdGuard一键安装脚本
  ---- By:方块君 ----
  (1) 安装 AdGuard
  (3) 退出
 "
 numsr_i
}
function menu_uinstall(){
echo -e "  AdGuard一键安装脚本
  ---- By:方块君 ----
  (1) 卸载 AdGuard
  (3) 退出
 "
 numsr_u
}
function numsr_i(){
echo && stty erase '^H' && read -p "请输入数字 [1-2]：" num
case "$num" in
	1)
	Install
	;;
	2)
	quit
	;;
esac
}
function numsr_u(){
echo && stty erase '^H' && read -p "请输入数字 [1-2]：" num
case "$num" in
	1)
	uinstall
	;;
	2)
	quit
	;;
esac
}
function quit(){
    cd /root/
    rm -rf /root/install.sh
	exit 1
}
function uinstall(){
killall AdGuardHome
rm -rf /root/AdGuardHome/
echo '卸载完成'
quit
}
function Install(){
cd 
wget -c https://dl.nayuli.com/AdGuardHome/releases/download/v0.107.6/AdGuardHome_linux_arm64.tar.gz -O AdGuardHome.tar.gz
tar -zxvf AdGuardHome.tar.gz
nohup /root/AdGuardHome/AdGuardHome "-s" "run" > /tmp/null 2>&1 &
echo '
请添加开机执行的计划任务 代码如下
nohup /root/AdGuardHome/AdGuardHome "-s" "run" > /tmp/null 2>&1 &'
echo '安装成功 请访问ip:3000进行设置'
quit
}
cd /root/
myFile="/root/AdGuardHome/AdGuardHome"
if [ ! -e "$myFile" ]; then
menu_install
else
menu_uinstall
fi